package com.xiaoyi.intentsdklibrary.SDK.FloatView;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.xiaoyi.intentsdklibrary.SDK.SDK;
import com.xiaoyi.intentsdklibrary.StateBarUtil;

public class NormalTopViewSDK {
    private static final NormalTopViewSDK ourInstance = new NormalTopViewSDK();
    private Handler mHandler;
    private WindowManager.LayoutParams mParams;
    private Runnable mR;
    private TextView mTopView;
    private WindowManager mWindowManager;

    public static NormalTopViewSDK getInstance() {
        return ourInstance;
    }

    private NormalTopViewSDK() {
    }

    public void init(Context context) {
        try {
            if (this.mWindowManager == null) {
                this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                TextView textView = new TextView(context);
                this.mTopView = textView;
                textView.setTextColor(-1);
                this.mTopView.setTextSize(10.0f);
                this.mTopView.setTypeface(Typeface.defaultFromStyle(1));
                this.mTopView.setGravity(17);
                this.mTopView.setBackgroundColor(Color.parseColor("#B0FF0000"));
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                this.mParams = layoutParams;
                layoutParams.flags = 1432;
                this.mParams.format = 1;
                if (Build.VERSION.SDK_INT >= 26) {
                    this.mParams.type = 2038;
                } else {
                    this.mParams.type = 2003;
                }
                this.mParams.gravity = 8388659;
                this.mParams.x = 0;
                this.mParams.y = 0;
                this.mParams.height = -1;
                this.mParams.height = StateBarUtil.getStatusBarHeight(context);
                this.mWindowManager.addView(this.mTopView, this.mParams);
                TextView textView2 = this.mTopView;
                if (textView2 != null) {
                    textView2.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void show(Context context, String str) {
        String str2;
        try {
            int i = SDK.nowNum + 1;
            int i2 = SDK.allNum;
            if (i >= i2) {
                str2 = str + "（" + i2 + "/" + i2 + "）";
            } else {
                str2 = str + "（" + i + "/" + i2 + "）";
            }
            this.mTopView.setVisibility(View.VISIBLE);
            this.mTopView.setText(str2);
            this.mWindowManager.updateViewLayout(this.mTopView, this.mParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void hide() {
        try {
            this.mTopView.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
